﻿using Api.Dal;
using Api.Model;

namespace Api.Bll
{
    public class CommentBll
    {
        public int count { get; set; }
        public List<Comment> GetComment(Comment comment)
        {
            List<Comment> co = CommentDAL.getComment(comment);
            return co;
        }
        public int InsertComment(Comment comment)
        {
            User u = UserDal.GetUserById(comment.ownerId);
            if (u == null)
            {
                throw new Exception("用户不存在");
                return 0;
            }
            if (u.isForbidden == true)
            {
                Console.WriteLine("用户被禁言");
                return -1;
            }
            count++;
            comment.id = count;
            comment.time = DateTime.Now;
            return CommentDAL.InsertComment(comment);
        }
        public bool UpdateComment(Comment comment)
        {
            return CommentDAL.UpdateComment(comment);
        }
        public bool DeleteComment(int cid)
        {
            return CommentDAL.DeleteCommentById(cid);
        }
    }
}
